import javax.swing.JOptionPane;

public abstract class ActionOrder extends Order{

    protected Player Owner;
    protected Territory Source;
    protected Territory Destination;
    protected int[] TroopAmount;
    protected String[] TechnologyName = {"Infantry", "Automatic Weapons", "Rocket Launchers", "Tanks", "Improved Tanks", "Fighter Planes"};
    
    public ActionOrder(Player _Owner, Territory _Source, Territory _Destination, int[] _TroopAmount){
        Owner = _Owner;
        Source = _Source;
        Destination = _Destination;
        TroopAmount = _TroopAmount.clone();
    }

    public Territory getSource(){return Source;}
    public void setSource(Territory r){Source = r;}
    public Territory getDestination(){return Destination;}
    public void setDestination(Territory d){Destination = d;}
    public int[] getTroopAmount(){return TroopAmount;}
    public int getTroopAmount(int index){return TroopAmount[index];}
    public void setTroopAmount(int[] _TroopAmount){TroopAmount = _TroopAmount.clone();}
    public void setTroopAmount(int index, int n){TroopAmount[index] = n;}
    
    public boolean checkOrder(Map m){
        if ((! checkTroop()) || (! checkPath(m)) || (! checkOwner())) return false;
        return true;       
    }
    protected boolean checkTroop(){
        for (int i = 0; i < 6; i++)
    	  if (TroopAmount[i] > Source.getUsableTroopAmount(i)) {
    		  JOptionPane.showMessageDialog(null, "No enough" + TechnologyName[i] + "troops to move!");
    		  return false;
    	  }
    		  return true;
    }
    protected abstract boolean checkOwner();
    protected abstract String printOrder();
    protected abstract boolean checkPath(Map m);
}
